/* 
 功能菜单数据模拟
*/

import Mock from 'mockjs';
import { param2Obj } from '@/utils';

const count = 0;

const menuMap = {
    rootNode: {
        meta: {
            code: 200,
            message: ''
        },
        data: [
            { id: this.count++ , name: '长庚平台' }
        ]
    },
    hasChildrenNode: {
        meta: {
            code: 200,
            message: ''
        },
        data: [
            { id: this.count++ , name: '功能1' },
            { id: this.count++ , name: '功能2' }
        ]
    },
    notHasChildrenNode: {
        meta: {
            code: 404,
            message: ''
        },
        data: []
    },
    isExist: {
        meta: {
            code: 404,
            message: ''
        },
        data: []
    },
    getFunctionById: {
        meta: {
            code: 200,
            message: ''
        },
        data: {
            id: '123456',
            name: '长庚平台',
            isMenu: true,
            belongId: '1111111111111111',
            url: '/home',
            active: false
        }
    }
}

const hasChildren = false;


export default {
    getRootNode: config => {
        return menuMap['rootNode'];
    },
    getChildrenNode: config => {
        // 此方法是get
        // 获得url中的参数
        // const { id } = param2Obj(config.url);
        const url = config.url;
        const param = url.split('/');
        const id = param[param.length - 1];

        if ( id < 10) {
            this.hasChildren = true;
        } else {
            this.hasChildren = false;
        }

        if (this.hasChildren) {
            return menuMap['hasChildrenNode'];
        } else {
            return menuMap['notHasChildrenNode'];
        }
    },
    addFunction: () => {
        return menuMap['rootNode'];
    },
    updateFunction: () => {
        return menuMap['rootNode'];
    },
    exist: () => {
        return menuMap['isExist'];
    },
    getFunctionById: () => {
        return menuMap['getFunctionById'];
    },
    deleteFunction: () => {
        return menuMap['rootNode'];
    }

}